package view.notes;

import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.notes.Note;
import model.notes.Note.NoteName;
import model.notes.impl.NoteImpl;

public abstract class AbstractNoteDecompositionJPanel extends JPanel {

	JComboBox jComboBox;
	JButton okButton;
	JLabel secondeMineureLabel;
	JLabel secondeMineureValue;
	JLabel secondeMajeureLabel;
	JLabel secondeMajeureValue;
	JLabel tierceMineureLabel;
	JLabel tierceMineureValue;
	JLabel tierceMajeureLabel;
	JLabel tierceMajeureValue;
	JLabel quarteLabel;
	JLabel quarteValue;
	JLabel quinteMineureLabel;
	JLabel quinteMineureValue;
	JLabel quinteLabel;
	JLabel quinteValue;
	JLabel quinteMajeureLabel;
	JLabel quinteMajeureValue;
	JLabel sixteLabel;
	JLabel sixteValue;
	JLabel septiemeMineureLabel;
	JLabel septiemeMineureValue;
	JLabel septiemeMajeureLabel;
	JLabel septiemeMajeureValue;

	JLabel decompositionLabel;
	JLabel choixLabel;

	public AbstractNoteDecompositionJPanel() {
		super();
		initComponent();
	}

	public AbstractNoteDecompositionJPanel(LayoutManager layout) {
		super(layout);
		initComponent();
	}

	private void initComponent() {
		this.secondeMineureLabel = new JLabel("Seconde mineure : ");
		this.secondeMineureValue = new JLabel();
		this.secondeMajeureLabel = new JLabel("Seconde majeure : ");
		this.secondeMajeureValue = new JLabel();
		this.tierceMineureLabel = new JLabel("Tierce mineure : ");
		this.tierceMineureValue = new JLabel();
		this.tierceMajeureLabel = new JLabel("Tierce majeure : ");
		this.tierceMajeureValue = new JLabel();
		this.quarteLabel = new JLabel("Quarte : ");
		this.quarteValue = new JLabel();
		this.quinteMineureLabel = new JLabel("Quinte mineure : ");
		this.quinteMineureValue = new JLabel();
		this.quinteLabel = new JLabel("Quinte juste : ");
		this.quinteValue = new JLabel();
		this.quinteMajeureLabel = new JLabel("Quinte majeure : ");
		this.quinteMajeureValue = new JLabel();
		this.sixteLabel = new JLabel("Sixte : ");
		this.sixteValue = new JLabel();
		this.septiemeMineureLabel = new JLabel("Septième mineure : ");
		this.septiemeMineureValue = new JLabel();
		this.septiemeMajeureLabel = new JLabel("Septième majeure : ");
		this.septiemeMajeureValue = new JLabel();
		this.jComboBox = new JComboBox(NoteName.values());
		this.okButton = new JButton("OK");
		this.okButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				NoteName noteName = (NoteName) AbstractNoteDecompositionJPanel.this.jComboBox
						.getSelectedItem();
				Note note = new NoteImpl(noteName);
				AbstractNoteDecompositionJPanel.this.secondeMineureValue.setText(note
						.getSecondeMineure(true).toString());
				AbstractNoteDecompositionJPanel.this.secondeMajeureValue.setText(note
						.getSecondeMajeure(true).toString());
				AbstractNoteDecompositionJPanel.this.tierceMineureValue.setText(note
						.getTierceMineure(true).toString());
				AbstractNoteDecompositionJPanel.this.tierceMajeureValue.setText(note
						.getTierceMajeure(true).toString());
				AbstractNoteDecompositionJPanel.this.quarteValue.setText(note.getQuarte(true)
						.toString());
				AbstractNoteDecompositionJPanel.this.quinteMineureValue.setText(note
						.getQuinteMineure(true).toString());
				AbstractNoteDecompositionJPanel.this.quinteValue.setText(note.getQuinte(true)
						.toString());
				AbstractNoteDecompositionJPanel.this.quinteMajeureValue.setText(note
						.getQuinteMajeure(true).toString());
				AbstractNoteDecompositionJPanel.this.sixteValue.setText(note.getSixte(true)
						.toString());
				AbstractNoteDecompositionJPanel.this.septiemeMineureValue.setText(note
						.getSeptiemeMineure(true).toString());
				AbstractNoteDecompositionJPanel.this.septiemeMajeureValue.setText(note
						.getSeptiemeMajeure(true).toString());
			}
		});

		this.decompositionLabel = new JLabel("Décomposition : ");
		this.decompositionLabel.setBorder(BorderFactory.createEmptyBorder(20,
				0, 10, 0));
		this.choixLabel = new JLabel("Choisissez une note : ");
		this.choixLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));

		setLayoutAndAddCommponents();
	}

	protected abstract void setLayoutAndAddCommponents();
}
